package com.ext.denacos.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class TestController1 {

    @Qualifier("redisTemplate")
    @Autowired
    private RedisTemplate template;

    @GetMapping("/get10")
    public String getname(HttpServletRequest request, Model model) {
        //HttpSession session = request.getSession();
        Map<String, String> map = getHeadersInfo(request);
        String id = map.get("token");
        log.info(id + "---------------------------");
        String id1 = template.opsForValue().get("token:").toString();
        if (id.equals(id1)) {
            log.info(id1 + "---------------");
        }
        return "success";
    }


    public Map<String, String> getHeadersInfo(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = request.getHeader(key);
            map.put(key, value);
        }
        return map;
    }
}
